#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void solve() {
    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    set<ll> s(a.begin(), a.end());
    vector<ll> ans;
    if (s.size() + 2 <= n) {
        for (ll i = 1; i <= n && ans.size() < 3; i++)
            if (s.count(i) == 0)
                ans.push_back(i);
        if (ans.size() != 3) {
            ans.push_back(a.back());
        }

    } else if (s.size() + 1 == n) {
        ll x = -1, y = -1, z = a.back();
        for (ll i = 1; i <= n; i++)
            if (s.count(i) == 0)
                x = i;
        y = a[n - 1] == a[n - 2] ? a[n - 3] : a[n - 2];
        ans = vector<ll>{x, y, z};
    } else {
        ans = vector<ll>{a[n - 3], a[n - 2], a[n - 1]};
    }

    for (ll i = 0; i < k; i++) {
        cout << ans[i % 3] << ' ';
    }
    cout << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t-- > 0) solve();

    return 0;
}